var server = require('../../../utils/server');

Page({
  data: {
    list: [],
    sort: 1,
    rank: ['', 'num', 'integral'],
  },
  sort: function (e) {
    var that = this;
    var sort = e.currentTarget.dataset.sort;
    that.setData({
      sort: sort,
    })
    if (sort !== 1 && sort !== undefined) {
      var rank = that.data.rank;
      rank = rank[sort - 1];
      var uid = getApp().globalData.userInfo.user_id;
      var data = {};
      data.uid = uid;
      data.rank = rank;
      that.list(data);
    }

  },
  onLoad: function (options) {
    var uid = getApp().globalData.userInfo.user_id;
    var data = {};
    data.uid = uid;
    this.list(data);
  },
  list: function (data) {
    var that = this;
    server.postJSON("/Activity/group_list", data, function (e) {
      that.setData({
        goods: e.data.result,
        // banner: e.data.banner
      })
      console.log(e)
    })
  },
  onReachBottom: function () {
    // if (!keywords)
    //   this.getGoods(categoryId, ++cPage, gsort + "-" + asc);
    // else
    //   this.getGoodsByKeywords(keywords, ++cPage, gsort + "-" + asc);
    // wx.showToast({
    //   title: '加载中',
    //   icon: 'loading'
    // })
  },
  onPullDownRefresh: function () {
    this.setData({
      goods: []
    });
    cPage = 0;
    if (!keywords)
      this.getGoods(categoryId, cPage, gsort + "-" + asc);
    else
      this.getGoodsByKeywords(keywords, cPage, gsort + "-" + asc);
  },
  tapGoods: function (e) {
    var objectId = e.currentTarget.dataset.objectId;
    wx.navigateTo({
      url: "/pages/goods/groupDetail/detail?objectId=" + objectId
    });
  },
});